﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Service
{
    public partial class OrderAdd : PageBaseService
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string serviceid = Request["serviceid"]??"";
            string userid = Request["userid"]??"";
            string secretkey = Request["secretkey"] ?? "";

            if (!IsValidKey(secretkey, serviceid, userid))
            {
                Response.Write("112");//密钥不正确
                return;
            }
            if (Request["serviceid"] != null && Request["userid"] != null)
            { 
                Model.ServiceInfo service = BLL.ServiceInfoBLL.Instance.GetDetail(serviceid);
                if (service == null)
                {
                    Response.Write("300");//无效的服务
                    return;
                }
                Model.UserInfo user = BLL.UserInfoBLL.Instance.GetDetail(userid);
                if (user == null)
                {
                    Response.Write("301");//无效的用户
                    return;
                }

                BLL.OrderInfoBLL.Instance.OrderService(serviceid, userid,null);
            }
            else
            {
                Response.Write("111");//参数不正确 
            }
        }

        private bool IsValidKey(string secretkey, string serviceid, string userid)
        {
            if (secretkey_enable)
            {
                if (string.IsNullOrEmpty(secretkey))
                {
                    return false;
                }
                else
                {
                    string finalkey = base.EncryptMD5(secretkey + current_day + serviceid + userid).Substring(6, 22);
                    return finalkey == secretkey;
                }
            }
            else
            {
                return true;
            }
        }
    }
}